﻿using System;

namespace DAPNet
{
    public class NaiveDetector : IClickDetector
    {
        private double treshold;

        private DerivativeFilter derivativeFilter;


        public NaiveDetector(double treshold, int hpfOrder)
        {
            this.treshold = treshold;
            derivativeFilter = new DerivativeFilter(hpfOrder);
        }

        internal double Treshold
        {
            get 
            { 
                return treshold; 
            }
            set 
            { 
                treshold = value; 
            }
        }

        internal int Order
        {
            get 
            { 
                return derivativeFilter.Order; 
            }
            set 
            { 
                derivativeFilter.Order = value; 
            }
        }

        public ClickDetection Detect(SampleCollection samples)
        {
            SampleCollection filteredSamples = samples.Clone();
            derivativeFilter.Process(filteredSamples);

            ClickDetection detection = new ClickDetection(samples.Count);
            for (int i = 0; i < filteredSamples.Count; i++)
            {
                double filteredValue = filteredSamples[i].Value;
                detection[i] = Math.Abs(filteredValue) > Math.Abs(treshold);
            }
            return detection;
        }
    }
}
